import pytest
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from common.keyword import Keyword


@pytest.fixture(scope='session')
def driver():
    # 定义全局变量driver
    global driver
    # 创建浏览器选项
    options = webdriver.ChromeOptions()
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_argument('disable-gpu')
    options.add_argument("disable-component-update")
    # 使用指定的浏览器驱动
    service = Service(r".\chromedriver_137.0.7151.68.exe")
    driver = webdriver.Chrome(options=options, service=service)
    # 执行用例，返回driver
    yield driver
    driver.close()
    # 用例执行完毕，关闭浏览器
    driver.quit()


@pytest.fixture(scope='session')
def keyword(driver):
    """
    定义全局变量keyword
    """
    return Keyword(driver)
